<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script src="js/jquery-3.7.1.js"></script>
</head>
<body>
    <table>
        <tr>
            <td align="right">用户名：</td>
            <td><input type="text" id="userName"></td>
        </tr>
        <tr>
            <td align="right">密码：</td>
            <td><input type="text" id="pwd"></td>
        </tr>
    </table>
    <button id="login">登录</button>
    <span id="error"></span>
<script>
    $("#login").click(function(){
        $.ajax("login.do",{
            type:"post",
            data:{
                userName:$("#userName").val(),
                pwd:$("#pwd").val()
            },
            success:function(data){
                if(data == "登录成功"){
                    localStorage.setItem("userName",$(userName).val());
                    location.href = 'welcome.html';
                }else{
                    $("#error").text(data).css("color","red");
                }
            }
        });
    });
</script>
</body>
</html>